<?php
     /**************************************************************************************
     * Bookswapp is a web application which allow students to exchange their textbooks
     * It is developed by students of ITE "C. Colamonico" - Sistemi Informativi Aziendali
     * Acquaviva delle Fonti (BA) - Italy
     *
     * Bookswapp is free software; you can redistribute it and/or modify it under
     * the terms of the GNU Affero General Public License version 3 as published by the
     * Free Software Foundation
     *
     * Bookswapp is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
     * details.
     *
     * You should have received a copy of the GNU Affero General Public License along 
     * with this program; if not, see http://www.gnu.org/licenses or write to the Free
     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     * 02110-1301 USA.
     *
     * You can contact ITE "C. Colamonico" with a mailing address at Via Colamonico, 5 
     * 70021 - Acquaviva delle Fonti (BA) Italy, or at email address bookswapp@itccolamonico.it.
     *
     * The interactive user interfaces in original and modified versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU Affero General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the Bookswapp
     * logo and ITE "C. Colamonico" copyright notice. If the display of the logo is not reasonably
     * feasible for technical reasons, the Appropriate Legal Notices must display the words
     * "Copyright ITE C. Colamonico - http://www.itccolamonico.it - 2014. All rights reserved".
     ****************************************************************************************/
?>

<?php

/**
 * This is the model base class for the table "{{subject}}".
 * DO NOT MODIFY THIS FILE! It is automatically generated by giix.
 * If any changes are necessary, you must set or override the required
 * property or method in class "Subject".
 *
 * Columns in table "{{subject}}" available as properties of the model,
 * followed by relations of table "{{subject}}" available as properties of the model.
 *
 * @property string $id_subject
 * @property string $subject
 *
 * @property Adoption[] $adoptions
 */
abstract class BaseSubject extends GxActiveRecord {

	public static function model($className=__CLASS__) {
		return parent::model($className);
	}

        /**
	 * @return string the associated database table name
	 */
	public function tableName() {
		return '{{subject}}';
	}

        /**
         * @return the active record label (the user friendly name displayed in the views)
         */
	public static function label($n = 1) {
		return Yii::t('app', 'Subject|Subjects', $n);
	}

        /**
         *  @returns string|array The name of the representing column/s (array) for the table
         */
	public static function representingColumn() {
		return 'subject';
	}

        /**
	 * @return array validation rules for model attributes.
	 */
	public function rules() {
		return array(
			array('subject', 'required'),
			array('subject', 'length', 'max'=>60),
			array('id_subject, subject', 'safe', 'on'=>'search'),
		);
	}

        /**
	 * @return array relational rules.
	 */
	public function relations() {
		return array(
			'adoptions' => array(self::HAS_MANY, 'Adoption', 'subject_id'),
		);
	}

        /**
	 * The pivot model is used by GxActiveRecord::saveWithRelated().
         * @return array list of pivot models for each MANY_MANY relationship. 
	 */
	public function pivotModels() {
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */        
	public function attributeLabels() {
		return array(
			'id_subject' => Yii::t('app', 'Id Subject'),
			'subject' => Yii::t('app', 'Subject'),
			'adoptions' => null,
		);
	}

        /**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search() {
		$criteria = new CDbCriteria;

		$criteria->compare('id_subject', $this->id_subject, true);
		$criteria->compare('subject', $this->subject, true);

		return new CActiveDataProvider($this, array(
			'criteria' => $criteria,
		));
	}
}